package com.drug.web.controller.wms;

import com.drug.common.annotation.Log;
import com.drug.common.core.controller.BaseController;
import com.drug.common.core.domain.AjaxResult;
import com.drug.common.core.page.TableDataInfo;
import com.drug.common.enums.BusinessType;
import com.drug.common.utils.poi.ExcelUtil;
import com.drug.wms.domain.BusOverflowOrder;
import com.drug.wms.domain.BusOverflowOrderAddParam;
import com.drug.wms.domain.BusOverflowOrderVO;
import com.drug.wms.service.IBusOverflowOrderDetailsService;
import com.drug.wms.service.IBusOverflowOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报损报溢细单Controller
 *
 * @author ruoyi
 * @date 2021-12-05
 */
@RestController
@RequestMapping("/system/overflow")
@Api(description = "报损报溢单")
public class BusOverflowOrderController extends BaseController {
    @Autowired
    private IBusOverflowOrderDetailsService busOverflowOrderDetailsService;

    @Autowired
    private IBusOverflowOrderService busOverflowOrderService;

    /**
     * 查询报损报溢总单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @ApiOperation("查询报损报溢总单列表")
    @GetMapping("/list")
    public TableDataInfo list(BusOverflowOrderVO busOverflowOrder) {
        startPage();
        List<BusOverflowOrder> list = busOverflowOrderService.selectBusOverflowOrderList(busOverflowOrder);
        return getDataTable(list);
    }

    /**
     * 导出报损报溢总单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @ApiOperation("导出报损报溢总单列表")
    @Log(title = "报损报溢总单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusOverflowOrderVO busOverflowOrder) {
        List<BusOverflowOrder> list = busOverflowOrderService.selectBusOverflowOrderList(busOverflowOrder);
        ExcelUtil<BusOverflowOrder> util = new ExcelUtil<BusOverflowOrder>(BusOverflowOrder.class);
        return util.exportExcel(list, "报损报溢总单数据");
    }


    /**
     * 获取报损报溢细单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:details:query')")
    @ApiOperation("获取报损报溢单详情")
    @GetMapping(value = "/details/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(busOverflowOrderDetailsService.selectBusOverflowOrderDetailsById(id));
    }

    /**
     * 新增修改报损报溢单
     */
    @PreAuthorize("@ss.hasPermi('system:details:add')")
    @Log(title = "报损报溢细单", businessType = BusinessType.INSERT)
    @ApiOperation("新增修改报损报溢单")
    @PostMapping("/insertOrUpdateOrderAndDetails")
    public AjaxResult add(@RequestBody BusOverflowOrderAddParam busOverflowOrderAddParam) {
        return toAjax(busOverflowOrderDetailsService.insertBusOverflowOrderDetails(busOverflowOrderAddParam));
    }

    /**
     * 修改报损报溢单
     */
    @PreAuthorize("@ss.hasPermi('system:info:update')")
    @Log(title = "报损报溢单", businessType = BusinessType.UPDATE)
    @ApiOperation("提交报损报溢单")
    @PostMapping(value = "/updateOrder/{orderId}")
    public AjaxResult updateOrder(@PathVariable("orderId") String orderId) {
        return toAjax(busOverflowOrderService.updateBusOverflowOrder(orderId));
    }


    /**
     * 删除报损报溢单
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "报损报溢单" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult removeOrder(@PathVariable("id") String id) {
        return toAjax(busOverflowOrderService.deleteBusOverflowOrderByIds(id));
    }

    /**
     * 删除报损报溢细单
     */
    @PreAuthorize("@ss.hasPermi('system:details:remove')")
    @Log(title = "报损报溢细单" , businessType = BusinessType.DELETE)
    @DeleteMapping("/details/{id}")
    public AjaxResult remove(@PathVariable("id") String id) {
        return toAjax(busOverflowOrderDetailsService.deleteBusOverflowOrderDetailsByIds(id));
    }


}
